package com.tea.app.moudles.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.tea.common.common.util.result.Result;
import com.tea.common.entity.Store;
import com.tea.common.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

/**
 * 门店管理控制器
 */
@RestController
@RequestMapping("/api/user/stores")
@Api(tags = "门店管理")
@RequiredArgsConstructor
public class StoreController {

    private final StoreService storeService;

    /**
     * 分页查询门店列表
     */
    @GetMapping("/page")
    @ApiOperation("分页查询门店列表")
    public Result<IPage<Store>> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status) {
        
        // 构建查询条件
        LambdaQueryWrapper<Store> queryWrapper = new LambdaQueryWrapper<Store>()
                .like(name != null, Store::getName, name)
                .eq(status != null, Store::getStatus, status)
                .orderByDesc(Store::getId);
        
        // 执行分页查询
        IPage<Store> page = storeService.page(new Page<>(current, size), queryWrapper);
        
        return Result.ok(page);
    }
    
    /**
     * 获取门店详情
     */
    @GetMapping("/{id}")
    @ApiOperation("获取门店详情")
    public Result<Store> getById(@PathVariable Long id) {
        Store store = storeService.getById(id);
        if (store == null) {
            return Result.fail("门店不存在");
        }
        return Result.ok(store);
    }
    

    

}